06. Flask-Migrate - Part 4

Follow along! Interactive Workspace

Follow along the rest of the walk-throughs (below) to continue getting migrations set up on our Todo application.

Workspace

This section contains either a workspace (it can be a Jupyter Notebook workspace or an online code editor work space, etc.) and it cannot be automatically downloaded to be generated here. Please access the classroom with your account and manually download the workspace to your local machine. Note that for some courses, Udacity upload the workspace files onto https://github.com/udacity , so you may be able to download them there.

Workspace Information:

  • Default file path:
  • Workspace type: jupyter-lab
  • Opened files (when workspace is loaded): n/a

Working with existing data

ND004 C01 L06 03.6 Flask-Migrate

Review

ND004 C01 L06 03.7 Flask-Migrate

Takeaways

Overall Steps to Set Up & Run Migrations

  1. Bootstrap database migrate commands : link to the Flask app models and database, link to command line scripts for running migrations, set up folders to store migrations (as versions of the database)
  2. Run initial migration to create tables for SQLAlchemy models , recording the initial schema: ala git init && first git commit. Replaces use of db.create_all()
  3. Migrate on changes to our data models
    • Make changes to the SQLAlchemy models
    • Allow Flask-Migrate to auto-generate a migration script based on the changes
    • Fine-tune the migration scripts
    • Run the migration, aka “upgrade” the database schema by a “version”

It’s always helpful to read the docs!